var express = require('express');
var router = express.Router();
let mysql = require('mysql')
/* GET home page. */
/* router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
}); */
let config = {
  host: 'localhost',
  port: 3306,
  user: 'root',
  password: 'root',
  database: 'student'
};
let conn = mysql.createConnection(config);
conn.connect((err) => {
  if (err) {
    console.log('数据库连接失败');
  } else {
    console.log('数据库连接成功');
  }
})

router.get('/index', (req, res) => {
  let sql = `select path from zy`;
  conn.query(sql, (err, doc) => {
    if (err) {
      console.log('查询数据失败');
    } else {
    res.render('index.html', {doc:doc})
    }
  })
 
})

module.exports = router;
